package com.ckerchina.admin.ckadmin.dao;

import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import javax.persistence.TypedQuery;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.ckerchina.admin.ckadmin.cache.MemcachedService;
import com.ckerchina.admin.ckadmin.domain.AppUser;
import com.ckerchina.admin.ckadmin.utils.Page;

@Repository
public class AppUserDAO extends AbstractDao<AppUser, Long>{

	public AppUser findByMobile(String username) {
		List<AppUser> list = this.entityManager
				.createQuery("SELECT o FROM AppUser o WHERE o.mobile = ?", AppUser.class)
				.setParameter(1, username).getResultList();
		return list.size() > 0 ? list.get(0) : null;
	}

	public AppUser findByToken(String token) {
		List<AppUser> list = this.entityManager.createQuery("SELECT o FROM AppUser o WHERE o.token = ?", AppUser.class)
				.setParameter(1, token).getResultList();
		AppUser appUser = list.size() > 0 ? list.get(0) : null;
		return appUser;
	}
}
